home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP9_91.ARJ / BITCOUNT.C < prev    next >
Text File  |  1990-06-25  |  326b  |  16 lines

  1. /****** BIT COUNTER *************/
  2. bit_count(x)
  3. {
  4.         int n=0;
  5.  
  6.         if (x) do
  7.                 n++;
  8.         while(x=x&(x-1));
  9.         return(n);
  10. }/*******************************/
  11.  
  12. /*
  13. ** The loop will execute once for each bit of x set, this is in average
  14. ** twice as fast as the shift/test method.
  15. */
  16.